/*
 * Created on 2005-6-11
 *
 * To change the template for this generated file go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
package leeon.bbsbrower.util;

import java.io.File;
import java.io.FileInputStream;
import java.util.Enumeration;
import java.util.Properties;

import leeon.bbsbrower.BBSBrowerPlugin;

/**
 * @author Administrator
 *
 * To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
public class PropertyLoader {

	public static void main(String[] args) throws Exception {
	}
	
	
	private Properties pro = null;
	
	private PropertyLoader() {}
	
	private PropertyLoader(String path) throws Exception {
		pro = new Properties();
		File file = BBSBrowerPlugin.getRealFile(path);
		
		if (file.exists() && file.isFile()) {
			FileInputStream fis = new FileInputStream(file);
			pro.load(fis);
			fis.close();
		}
	}
	
	public static PropertyLoader newInstance(String path) {		
		try {
			
			PropertyLoader p = new PropertyLoader(path);
			if (p.pro != null) return p;
			else return null;
			
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}		
 
	}
	/**
	 * @param arg0
	 * @return
	 */
	public String getProperty(String arg0) {
		return pro.getProperty(arg0);
	}

	/**
	 * @param arg0
	 * @param arg1
	 * @return
	 */
	public String getProperty(String arg0, String arg1) {
		return pro.getProperty(arg0, arg1);
	}

	/**
	 * @return
	 */
	public Enumeration<?> propertyNames() {
		return pro.propertyNames();
	}

}
